<template>
	<div>

		<el-card>
			<el-form ref="ruleForm" :rules="rules" :model="form" label-width="80px">
				<el-row>
					<el-col :span="12">
						<el-form-item label="标题" prop="title">
							<el-input v-model="form.title" type="text"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				
				<el-row>
					<el-col :span="12">
						<el-form-item label="描述" prop="des">
							<el-input v-model="form.des" type="text"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				
				<el-form-item>
					<el-button size="medium" type="primary" @click="submitForm('ruleForm')" :loading="loading">提交
					</el-button>
				</el-form-item>
			</el-form>
		</el-card>

	</div>
</template>

<script>
	import editor from '@/components/editor/index';
	import upload from '@/components/upload.vue';
	import allRule from '@/common/rule.js';
	export default {
		components: {
			editor,
			upload
		},
		data() {
			return {
				loading: false,
				form: {
					id: "",
					title:'',
					des:""

				},
				rules: allRule,

			}
		},
		created() {
			if(this.$route.query){
				this.jiazai(this.$route.query)
			}
		},
		methods: {
			jiazai(e){
				this.axios.post("/api/index/findhelp", {
					id: e.id
				}).then(res => {
					this.form=res;
				}).catch(error => {
				
				})
			},
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						this.axios.post("/admin/user/addhelp", {
							title: this.form.title,
							des: this.form.des,
							id:this.form.id
						}).then(res => {
							this.$message.success({
								message: "添加成功",
								onClose: (res) => {
									this.$router.replace("/help")
								}
							})
						}).catch(error => {

						})
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
		}
	}
</script>

<style>
</style>
